package com.jing.product.controller;

import com.jing.common.core.domain.R;
import com.jing.common.core.web.controller.BaseController;
import com.jing.common.core.web.page.TableDataInfo;
import com.jing.product.domain.po.ProductCategory;
import com.jing.product.service.ProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author：HaoYunde
 * @Package：com.jing.product.controller
 * @Project：Jing
 * @name：ProductCategoryController
 * @Date：2024/5/23 19:51
 */
@RestController
@RequestMapping("productCategory")
@Validated
@Api(tags = "商品分类表")
public class ProductCategoryController extends BaseController {
    @Autowired
    private ProductCategoryService productCategoryService;


    /**
     * 查询商品分类表
     * @return
     */
    @GetMapping("findProductCategory")
    @ApiOperation(value = "查询商品分类表")
    public R findProductCategory(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                 @RequestParam(required = false, defaultValue = "10") Integer pageSize){
            startPage();
        List<ProductCategory> list=productCategoryService.findProductCategory();
        TableDataInfo dataTable = getDataTable(list);
        return R.ok(dataTable);
    }

    /**
     * 删除商品分类表
     * @param id
     * @return
     */
    @PostMapping("/delect")
    @ApiOperation(value = "删除商品分类表")
    public R delect(@Valid @RequestParam Integer id){
        productCategoryService.delect(id);
        return R.ok();
    }

    /**
     * 查询分类第二级
     * @param pageNum
     * @param pageSize
     * @param id
     * @return
     */
    @GetMapping("findProductCategoryEr")
    @ApiOperation(value = "查询商品分类二级表")
    public R findProductCategoryEr(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                 @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                   @RequestParam(required = false) Integer id){
        startPage();
        List<ProductCategory> list=productCategoryService.findProductCategoryEr(id);
        TableDataInfo dataTable = getDataTable(list);
        return R.ok(dataTable);
    }


    /**
     * 修改导航是否显示
     * @param id
     * @param navStatus
     * @return
     */
    @GetMapping("/updatenavStatus")
    @ApiOperation(value = "修改导航是否显示")
    public R updatenavStatus(@Valid @RequestParam Integer id,@RequestParam Integer navStatus){
        productCategoryService.updatenavStatus(id,navStatus);
        return R.ok("修改导航是否显示成功");
    }


    /**
     * 修改显示状态
     * @param id
     * @param showStatus
     * @return
     */
    @GetMapping("/updateshowStatus")
    @ApiOperation(value = "修改显示状态")
    public R updateshowStatus(@Valid @RequestParam Integer id,@RequestParam Integer showStatus){
        productCategoryService.updateshowStatus(id,showStatus);
        return R.ok("修改显示状态成功");
    }





}
